#!/bin/sh

status() {
        local pid
	PID=/usr/local/etc/rc.d/pidof

        # Test syntax.
        if [ $# = 0 ] ; then
                echo "Usage: status {program}"
                return 1
        fi

        # First try "pidof"
        pid=`$PID $1`
        if [ "$pid" != "" ] ; then
                echo "${1} (pid $pid) is running..."
                return 0
        fi

        # Next try "/var/run/*.pid" files
        if [ -f /var/run/${1}.pid ] ; then
                read pid < /var/run/${1}.pid
                if [ "$pid" != "" ] ; then
                        echo "${1} dead but pid file exists"
                        return 1
                fi
        fi
        # See if /var/spool/lock/${1} exists
        if [ -f /var/spool/lock/${1} ]; then
                echo "${1} dead but subsys locked"
                return 2
        fi
        echo "${1} is stopped"
        return 3
}

